#include "GY_ButtonDelegete.h"
#include <QPushButton>
#include <QMouseEvent>

GY_ButtonDelegete::GY_ButtonDelegete(QObject *parent)
    : QStyledItemDelegate(parent)
{

}

void GY_ButtonDelegete::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    QStyleOptionButton buttonStyle;
    buttonStyle.text = "我是按钮";
    buttonStyle.rect = option.rect;
    buttonStyle.state = QStyle::State_Enabled;
    QPushButton button;
    button.style()->drawControl(QStyle::CE_PushButton,&buttonStyle,painter,&button);
}

bool GY_ButtonDelegete::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
{
    QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
    if(option.rect.contains(mouseEvent->pos()))
    {
        if(mouseEvent->type() == QEvent::MouseButtonPress)
        {
            emit clicked(index);
        }
    }
    return true;
}
